/**
 * 
 */
package org.adorsys.aderp.cash.web;

import java.util.Date;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.adorsys.aderp.cash.domain.CashReceipt;
import org.adorsys.aderp.cash.web.ext.RemoteCallService;
import org.adorsys.aderp.cash.work.encashment.BasicEncashment;
import org.adorsys.aderp.cash.work.encashment.EncashmentSession;
import org.adorsys.aderp.jpa.security.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author Boris Waguia
 *
 */
@Controller
@RequestMapping(value="/collects")
public class CollectController {
	@Resource
	private RemoteCallService remoteCallService;
	
	
	@RequestMapping(method=RequestMethod.GET,params="start")
	public String create(HttpServletRequest request,HttpServletResponse response,Model uiModel){
		if(BasicEncashment.getActiveEncashmentSession() == null){
	        EncashmentSession encashmentSession = new EncashmentSession(request.getSession(false).getId(),new Date(),SecurityUtils.getUserName());
	        BasicEncashment.addEncashmentSession(encashmentSession);
		}
        return "redirect:/collects/cashregitems?form";
	}
	@RequestMapping(value="/confirm",params="param=true",method=RequestMethod.GET)
	public String confirmCollecting(HttpServletRequest request,HttpServletResponse response,Model uiModel){
		//get the cash receipt from all stored cashregitems.
		CashReceipt cashReceipt = BasicEncashment.getCashReceipt();
//		cashReceiptService.saveCashReceipt(cashReceipt);
		//send it for modifications.
//		return updateCashReceiptForm(cashReceipt, uiModel);
		return createCashReceiptForm(cashReceipt, uiModel);
	}
	
}
